using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace ProjectEuler
{
    internal class Problem30
    {
        public void Solve()
        {
            var nums=new List<int>(); 
            for (var i = 2; i < 10000000; i++)
            {
                var res = PowTheDigits(i, 5);
                if (res != i) continue;
                nums.Add(res);
                Debug.WriteLine("res = " + res);
            }

            var sum = nums.Sum();
            Debug.WriteLine("num count " + nums.Count + " sum = " + sum);
        }

        int PowTheDigits(double num, int power)
        {
            var theDiv = num;
            var sum = 0;
            while (theDiv > 1)
            {
                sum += (int)Math.Pow((int)(theDiv % 10), power);
                theDiv = theDiv / 10;
            }

            return sum;
        }
    }
}